

package org.koyabr.webx.demo.danmaku.dal.dao.ibatis;


import java.util.HashMap;
import java.util.List;

import org.koyabr.webx.demo.danmaku.dal.dao.PostDao;
import org.koyabr.webx.demo.danmaku.dal.dataobjs.Danmaku;
import org.koyabr.webx.demo.danmaku.dal.dataobjs.Post;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class IbatisPostDao extends SqlMapClientDaoSupport implements PostDao {
	
	public void insertDanmaku(Danmaku danmaku){
		getSqlMapClientTemplate().insert("insertDanmaku", danmaku);
	}
	
	@SuppressWarnings("unchecked")
	public List<Danmaku> getDanmakusByPostId(String id){
		return getSqlMapClientTemplate().queryForList("getDanmakusByPostId", id);
	}
	
	public void insertPost(Post post){
		getSqlMapClientTemplate().insert("insertPost", post);
	}
	
	public Post getPostById(String postId){
		return (Post) getSqlMapClientTemplate().queryForObject("getPostById", postId);
	}
	public Post getPostByTitle(String title){
		return (Post) getSqlMapClientTemplate().queryForObject("getPostByTitle", title);
	}
	
	@SuppressWarnings("unchecked")
	public List<Post> getPostsByCategory(String category, String sortSeed, String sortOrder){
		
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("category", category);
		map.put("sortSeed", sortSeed);
		map.put("sortOrder", sortOrder);
		
		return getSqlMapClientTemplate().queryForList("getPostsByCategory", map);
	}
	@SuppressWarnings("unchecked")
    public List<Post> getPostsByAuthor(String username, String sortSeed, String sortOrder){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("username", username);
		map.put("sortSeed", sortSeed);
		map.put("sortOrder", sortOrder);
		
		return getSqlMapClientTemplate().queryForList("getPostsByAuthorName", map);
    	
    }
	@SuppressWarnings("unchecked")
    public List<Post> getPostsByAutAndCat(String username, String category, String sortSeed, String sortOrder){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("username", username);
		map.put("category", category);
		map.put("sortSeed", sortSeed);
		map.put("sortOrder", sortOrder);
		
		return getSqlMapClientTemplate().queryForList("getPostsByCategoryAndAuthorName", map);
    }
	@SuppressWarnings("unchecked")
    public List<Post> getAllPosts(String sortSeed, String sortOrder){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("sortSeed", sortSeed);
		map.put("sortOrder", sortOrder);
    	return getSqlMapClientTemplate().queryForList("getAllPosts", map);
    }



}
